import { request } from "~~/utils/fetch";
import type { Response } from "~~/types/common";
import type { User } from "~~/types/user";
import { reponseIntercept } from "@/utils";
import { http } from "../utils/http";
/**
 * @description 获取用户个人信息
 */
export const getUserInfo = (params?: any) => {
  return request<Response<{ user: User }>>({
    url: "/user",
    method: "post",
    body: params,
  });
};

/**
 * @description 获取用户昵称信息
 */
export const getTwUserInfo = (params: any) => {
  return request<Response<{ userInfo: UserInfo }>>({
    url: "/tw-userInfo",
    method: "post",
    body: params,
  });
};

/**
 * @description 获取用户实名认证状态
 */
export const getUserIdentifyStatus = (params: any) => {
  return request({
    url: "/bd/pc/identifyStatus",
    method: "post",
    body: params,
  }).then(reponseIntercept);
};

/**
 * @description 查询用户BDC账户
 */
export const getUserAccount = http.Post(
  "/msa/traded-api-bdc/account/acr/queryAccountAsset"
);

// 获取当前我的可用积分
export const getMyIntergral = (data: any) =>
  request({
    url: "/integral/my",
    method: "post",
    body: data,
  });

/**
 * @description: 登录
 */
export const loginUser = http.Post("/login");

// 邮箱后缀规则
export const containsEmail = http.Post("/contains-email");

/**
 * @description: 三方登录是否注册过
 */
export const openID = http.Post("/openID-check");

/**
 * @description: 邮箱注册
 */
export const newMailboxRegister = http.Post("/v5/new-mailbox-register");

/**
 * @description: 邮箱验证码 注册
 */
export const newMailboxRegisterCode = http.Post(
  "/v5/new-mailbox-register/code"
);

/**
 * @description: 三方登录/注册（校验openID）
 */
export const validateTripartiteLogin = http.Post("/validate/tripartite-login");

/**
 * @description:  hcaptcha配置信息
 */
export const hcaptchaValidateInfo = http.Post("/hcaptcha/validate/info");

/**
 * @description: hcaptcha验证
 */
export const hcaptchaValidateGetEmailCode = http.Post(
  "/hcaptcha/validate/get-email-code"
);

/**
 * @description: 邮箱验证码,前置验证
 */
export const preValidation = http.Post("/pre/validation");

/**
 * @description: BTC邀请信息接口-使用手续费
 */
export const inviteInfoApp = http.Post("/activity/btc/invite-info");

/**
 *
 * @description 文件流上传图片
 */
export const uploadFileStream = (params: { image: File }) => {
  const formData = new FormData();

  formData.append("image", params.image);

  return request<{
    path: string;
    id: number;
  }>({
    url: "/fileStream",
    method: "post",
    headers: {
      "Content-Type": "multipart/form-data",
    },
    body: formData,
  });
};
